<template>
  <MyCard title="男女比例">
    <div class="sex">
      <div class="top">
        <div>
          <span>男士</span>
          <img src="../../images/man.png" alt="" />
        </div>
        <div>
          <span>女士</span>
          <img src="../../images/woman.png" alt="" />
        </div>
      </div>
      <div class="bootom">
        <span>男士60%</span>
        <span>女士40%</span>
      </div>
      <div class="charts" ref="charts"></div>
    </div>
  </MyCard>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';
const charts = ref();

onMounted(() => {
  // 获取echarts类的实例
  const myCharts = echarts.init(charts.value);
  // 设置实例的配置项
  myCharts.setOption({
    //标题组件
    title: {
      // text: '男女比例',
    },
    textStyle: {
      color: 'skyblue',
    },
    xAxis: {
      show: false,
      min: 0,
      max: 100,
    },
    yAxis: {
      show: false,
      type: 'category',
    },
    series: [
      {
        type: 'bar',
        data: [60],
        barWidth: 20,
        z: '100',
        itemStyle: {
          color: '#007AFE',
          borderRadius: 20,
        },
      },
      {
        type: 'bar',
        data: [100],
        barWidth: 20,
        barGap: '-100%',
        itemStyle: {
          color: '#FF4B7A',
          borderRadius: 20,
        },
      },
    ],
    grid: {
      left: 70,
      top: 0,
      right: 70,
      bottom: 20,
    },
  });
});
</script>

<style lang="scss" scoped>
.sex {
  flex: auto;
  margin-top: 30px;
  display: grid;
  grid-template-rows: 1.5fr 0.5fr 0.5fr;

  .top {
    display: flex;
    justify-content: space-evenly;
    align-items: center;

    > div {
      width: 100px;
      height: 120px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;

      &:first-child {
        background: url('../../images/man-bg.png') no-repeat;
        background-size: 100% 100%;
      }

      &:last-child {
        background: url('../../images/woman-bg.png') no-repeat;
        background-size: 100% 100%;
      }

      span {
        position: absolute;
        top: 3px;
        color: white;
      }
    }
  }

  .bootom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    margin: 0 80px;
  }
  .charts {
  }
}
</style>
